Logo
Spacer News Wiki Features F.A.Q. Team members Screenshots Download Messageboard Bug tracker Submit files
Top divider

Lua OpenGL Api

Contents

[edit] Spring

gl.GetSun

 ()        -> number sunPosX, number sunPosY, number sunPosZ
 ( "pos" ) -> number sunPosX, number sunPosY, number sunPosZ
 ( "shadowDensity" [, "unit"] ) -> number shadowDensity
 ( "diffuse"       [, "unit"] ) -> nil | number r, number g, number b
 ( "ambient"       [, "unit"] ) -> nil | number r, number g, number b
 ( "specular" )                 -> nil | number r, number g, number b

gl.ConfigScreen

 ( number screenWidth, number screenDistanc e) -> nil

gl.DrawMiniMap

 () -> nil

gl.SlaveMiniMap

 ( boolean mode ) -> nil

gl.ConfigMiniMap

 ( int px, int py, int sx, int sy ) -> nil

gl.GetViewSizes

 ( ) -> number x, number y

[edit] Basics

gl.PushMatrix

 () -> nil

gl.PopMatrix

 () -> nil

gl.Translate

 (number x, number y, number z) -> nil

gl.Scale

 (number x, number y, number z) -> nil

gl.Rotate

 (number angle, number x, number y, number z) -> nil

gl.Color

 ( { number r, number g, number b[, number a] } |
     number r, number g, number b[, number a] ) -> nil

gl.LineWidth

 ( number width ) -> nil

gl.PointSize

 ( number size ) -> nil

gl.Billboard use this to draw 2d primitives in DrawWorld

 () -> nil

gl.ResetState

 () -> nil

 ShadeModel = GL_SMOOTH
 Scissor    = false
 Texture    = false
 ColorMask  = true, true, true, true
 DepthMask  = false
 DepthTest  = false  (GL_LEQUAL)
 Culling    = false  (GL_BACK)
 LogicOp    = false  (GL_INVERT)
 AlphaTest  = false  (GL_GREATER, 0.5f)
 Blending   = GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

gl.ResetMatrices

 () -> nil

 Resets GL_TEXTURE matrix stack
 Resets GL_MODELVIEW matrix stack
 Resets GL_PROJECTION matrix stack

gl.Clear

 ( GL.DEPTH_BUFFER_BIT, number cleardepth ) -> nil
 ( GL.STENCIL_BUFFER_BIT, int clearstencil ) -> nil
 ( GL.COLOR_BUFFER_BIT | GL.ACCUM_BUFFER_BIT, number r, number g, number b, number a ) -> nil

[edit] Draw Basics

gl.BeginEnd

 ( number GLType, function [, arg1,... ] ) -> nil

gl.Vertex

 ( { number x, number y [, number z [, number w ]] } |
   number x, number y |
   number x, number y, number z |
   number x, number y, number z, number w ) -> nil

gl.Normal

 (  number x, number y, number z |
  { number x, number y, number z } ) -> nil

gl.Rect

 ( number x1, number y1, number x2, number y2 ) -> nil

gl.TexRect texture rect

 ( number x1, number y1, number x2, number y2,
 [ boolean flip_s, boolean flip_t | number s1, number t1, number s2, number t2 ] ) -> nil

gl.Shape

( number GLtype,
  elements = {
    [1] = { v | vertex   = { number x, number y, number z },           required
            n | normal   = { number x, number y, number z },           optional
            t | texcoord = { number x, number y },                     optional
            c | color    = { number r, number g, number b, number a }  optional
    },
    etc ...
  }
) -> nil

[edit] Text

gl.Text

 (string "text", number x, number y, number size, string "options")

 options:
 'c' = center
 'r' = right
 'n' = deactives colorCodes (so you can use gl.Color() to write transparent text etc.)
 'o' = black outline
 'O' = white outline

gl.GetTextWidth

 (string "text") -> number width  --  in pixels, with a font size of 1.0

[edit] Unit/Feature Draw Functions

gl.Unit (draws the unit)

 ( number unitID, [ boolean rawdraw, int lod ] ) -> nil

gl.UnitRaw (redundant -> use gl.Unit instead!)

 ( number unitID, [ boolean rawdraw, int lod ] ) -> nil

gl.UnitShape

 ( number unitDefID, number teamID ) -> nil

gl.Feature

 ( number featureID ) -> nil

gl.FeatureShape

 ( number featureDefID, number teamID ) -> nil

gl.UnitMultMatrix (world space -> unit space)

 ( number unitID ) -> nil

gl.UnitPieceMultMatrix (unit space -> piece space)

 ( number unitID, int piece ) -> nil

gl.UnitPiece (draws the unit piece)

 ( number unitID, int piece ) -> nil

gl.UnitPieceMatrix (use gl.UnitPieceMultMatrix instead!)

 ( number unitID, int piece ) -> nil

gl.DrawListAtUnit

 ( number unitID, number listID, [ boolean midPos,
     number scaleX, number scaleY, number scaleZ,
     number degrees, number rotX, number rotX, number rotZ ] ) -> nil 

gl.DrawFuncAtUnit

 ( number unitID, boolean midPos, function [, arg1,... ]) -> nil

[edit] Switches

gl.Blending

 ( boolean enable | number srcmode, number dstmode ) -> nil

gl.AlphaTest

 ( boolean enable | number func, number threshold ) -> nil

gl.DepthTest

 ( boolean enable | number func ) -> nil

gl.Culling

 ( boolean enable | number face ) -> nil

gl.DepthMask

 ( boolean enable ) -> nil

gl.ColorMask

 ( boolean ) -> nil
 ( boolean r, boolean g, boolean b, boolean a ) -> nil

gl.LogicOp

 ( boolean enable | number func ) -> nil

gl.Fog

 ( boolean enable ) -> nil

gl.Smoothing

( (boolean enable | number POINT), 
  (boolean enable | number LINE),
  (boolean enable | number POLYGON) ) -> nil

gl.EdgeFlag

( boolean enable ) -> nil

gl.Scissor

 ( boolean ) -> nil
 ( int x, int y, int w, int h ) -> nil

gl.LineStipple

 ( string any ) -> nil (use springs default line stipple)
 ( boolean enable ) -> nil
 ( int factor, number pattern ) -> nil

gl.PolygonMode

 ( number face, number mode ) -> nil

gl.PolygonOffset

 ( boolean enable | number factor, number units ) -> nil

[edit] Textures

gl.Texture

 ( [ number texNum, ] boolean enable | string name ) -> nil | boolean loaded

                          current formats:
 :${opt}:/LuaUI/images/image.png = filename
                             #12 = unitDef 12 buildpic
                           %34:1 = unitDef 34 s3o tex2 (:0->tex1,:1->tex2)
                             !56 = lua generated texture 56
                          $units = 3do textureatlas
                         $shadow = shadowmap
                       $specular = specular cube map
                     $reflection = reflection cube map
                        possible ${opt}'s are:
                             'n' = nearest
                             'l' = linear
                             'a' = aniso
                             'i' = invert
                             'g' = greyed
                             'c' = clamped
                             'b' = border
                             't' = tint (don't know how to use it, sorry)
                example: ":iac:/LuaUI/images/image.png"

gl.CreateTexture

 ( int xsize, int ysize,
 [ { 
   [target     = number,] (like GL_TEXTURE_1D,GL_TEXTURE_2D,...)
   [format     = number,]
   [min_filter = number,]
   [mag_filter = number,]
   [wrap_s     = number,]
   [wrap_t     = number,]
   [wrap_r     = number,]
   [aniso      = number,]
   [border     = boolean,]
   [fbo        = boolean,] (needs GLEW_EXT_framebuffer_object!)
   [fboDepth   = boolean] (needs GLEW_EXT_framebuffer_object!)
 } ]
 ) -> string

gl.DeleteTexture

 ( string texture ) -> boolean

gl.DeleteTextureFBO (needs GLEW_EXT_framebuffer_object!)

 ( string texture ) -> boolean

gl.TextureInfo

 ( string texture ) -> nil | {
     xsize = number,
     ysize = number,
     alpha = boolean, //not used yet
     type  = number,  //not used yet
   }

  the format of the texture string is the same as in gl.Texture()

gl.TexCoord

 ( number x | 
   number x, number y |
   number x, number y, number z |
   number x, number y, number z, number w |
   { number x [, number y [, number z [, number w ]]] } ) -> nil

gl.MultiTexCoord

 ( int texNum,
   number x |
   number x, number y |
   number x, number y, number z |
   number x, number y, number z, number w |
   { number x [, number y [, number z [, number w ]]] } ) -> nil

gl.TexEnv

 ( number target, number pname,
   number value |
   number var1, number var2, number var3 ) -> nil

gl.MultiTexEnv

 ( int texNum, number target, number pname,
   number value |
   number var1, number var2, number var3 ) -> nil

gl.TexGen

 ( number target,
   boolean state |
   number pname, number value |
   number pname, number var1, number var2, number var3 ) -> nil

gl.MultiTexGen

 ( int texNum, number target,
   boolean state |
   number pname, number value |
   number pname, number var1, number var2, number var3 ) -> nil       

gl.CopyToTexture

 (string texture, int xoff, int yoff, int x, int y, int w, int h 
 [,number target,number level])->nil

gl.RenderToTexture (needs GLEW_EXT_framebuffer_object!)

 ( string fbotexture, lua_func ) -> nil

gl.GenerateMipmap (needs glGenerateMipmapEXT!)

 ( string texture ) -> boolean

[edit] Lights

gl.Lighting

 ( boolean enable ) -> nil

gl.ShadeModel

 ( number mode ) -> nil

gl.Light

 ( int light, 
 boolean enable |
 number pname, number param |
 number pname, number param1, number param2, number param3 ) -> nil

gl.Material

 ({
   ambient   = {number r, number g, number b[, number a]},
   diffuse   = {number r, number g, number b[, number a]},
   ambidiff  = {number r, number g, number b[, number a]},
   emission  = {number r, number g, number b[, number a]},
   specular  = {number r, number g, number b[, number a]},
   shininess = number specularExponent
 }) -> nil

[edit] Display Lists

Display Lists save given vertex attributes in a static buffer, so the GPU can directly read them (without the CPU). Display Lists are a lot faster (10-60x) than standard drawing with glShape/glBeginEnd, so try to use them when ever you can. If you want to learn more about them, g00gle is your friend ;)

gl.CreateList

 ( function [,arg1 [,arg2...]] ) -> nil

gl.CallList

 ( number listID ) -> nil

gl.DeleteList

 ( number listID ) -> nil

[edit] Hardware relevant

gl.HasExtension

 ( string extname ) -> boolean

gl.GetNumber

 ( number ext, int count ) -> number [, number, number, ... #count ]

gl.GetString

 ( number ext ) -> string

[edit] DrawGroundPrimitives

gl.DrawGroundCircle

 ( number x, number y, number z, number radius, number divs [, number slope ] ) -> nil

gl.DrawGroundQuad Note: x1,z1,x2 & z2 are rounded, so don't use it for very small or moving objects

 ( number x1, number z1, number x2, number z2,
   [ boolean useNorm,
     [ number tu1, number tv1, number tu2, number tv2 |
       boolean useTextureCoord ] ] ) -> nil

[edit] Extended

gl.ActiveTexture

 ( int texNum, function [, arg1,... ] ) -> nil

gl.GetGlobalTexNames

 () -> { [1] = string texture, etc ... }

gl.GetGlobalTexCoords

 ( string tatexture ) -> number xstart, number ystart, number xend, number yend

gl.GetShadowMapParams

 () -> number xmid, number ymid, number p17, number p18

gl.GetMatrixData

 ( GL.PROJECTION [, int i] ) -> nil | number, etc.. | number Matrix[i]
 ( GL.MODELVIEW  [, int i] ) -> nil | number, etc.. | number Matrix[i] 
 ( GL.TEXTURE    [, int i] ) -> nil | number, etc.. | number Matrix[i]
 ( "shadow" )                -> nil | number, etc.. 
 ( "camera" )                -> nil | number, etc.. 
 ( "caminv" )                -> nil | number, etc.. 
 ( "camprj" )                -> nil | number, etc.. 
 ( "billboard" )             -> nil | number, etc.. 

gl.PointSprite (needs openGL2.0!)

 ( boolean enable, [boolean coord_replace, boolean coord_origin_upper] ) -> nil

gl.PointParameter (needs openGL2.0!)

 ( number v1, number v2, number v3, 
   [ number sizeMin, number sizeMax, number sizeFade ] ) -> nil

gl.SecondaryColor

 ( { number r, number g, number b } |
     number r, number g, number b ) -> nil

gl.FogCoord

 ( number value ) -> nil

gl.ClipPlane

 ( int plane, note: $plane can only be 1 or 2
 boolean enable |
 number A, number B, number C, number D ) -> nil

gl.MatrixMode

 ( number mode ) -> nil

gl.LoadIdentity

 () -> nil

gl.LoadMatrix

 () -> nil

gl.MultMatrix

gl.Ortho

 ( number left, number right, number bottom, number top, number near, number far ) -> nil

gl.Frustum

 ( number left, number right, number bottom, number top, number near, number far ) -> nil

gl.PushPopMatrix

gl.PushAttrib

 ( [ number attrib ] ) -> nil

gl.PopAttrib

 () -> nil

gl.Flush

 () -> nil

gl.Finish

 () -> nil

[edit] Shaders (GLSL)

 Lua_GLSL_Api

Retrieved from "http://spring.clan-sy.com/wiki/Lua_OpenGL_Api"

This page has been accessed 974 times. This page was last modified 15:30, 15 February 2008.